<template>
  <t-form ref="basicInfoForm" :data="info" :rules="rules" label-width="150px">
    <t-row class="mt10">
      <t-col :span="6" class="mb8">
        <t-form-item label="表名称" name="tableName">
          <t-input placeholder="请输入仓库名称" v-model="info.tableName" />
        </t-form-item>
      </t-col>
      <t-col :span="6" class="mb8">
        <t-form-item label="表描述" name="tableComment">
          <t-input placeholder="请输入" v-model="info.tableComment" />
        </t-form-item>
      </t-col>
      <t-col :span="6" class="mb8">
        <t-form-item label="实体类名称" name="className">
          <t-input placeholder="请输入" v-model="info.className" />
        </t-form-item>
      </t-col>
      <t-col :span="6" class="mb8">
        <t-form-item label="作者" name="functionAuthor">
          <t-input placeholder="请输入" v-model="info.functionAuthor" />
        </t-form-item>
      </t-col>
      <t-col :span="12" class="mb8">
        <t-form-item label="备注" name="remark">
          <t-textarea :rows="3" v-model="info.remark"></t-textarea>
        </t-form-item>
      </t-col>
    </t-row>
  </t-form>
</template>

<script setup>
defineProps({
  info: {
    type: Object,
    default: null,
  },
});

// 表单校验
const rules = ref({
  tableName: [{ required: true, message: "请输入表名称", trigger: "blur" }],
  tableComment: [{ required: true, message: "请输入表描述", trigger: "blur" }],
  className: [{ required: true, message: "请输入实体类名称", trigger: "blur" }],
  functionAuthor: [{ required: true, message: "请输入作者", trigger: "blur" }],
});

const basicInfoForm = ref(null);

const validate = () => {
  return new Promise((resolve) => {
    basicInfoForm.value.validate().then((valid) => {
      resolve(valid);
    });
  });
};

defineExpose({
  validate,
});
</script>
